﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeReborn.Classes
{
    public class Globals
    {

        /// <summary>
        /// Internal singleton instance of this class.
        /// </summary>
        private static Globals m_Instance;

        /// <summary>
        /// Private Constructor
        /// </summary>
        private Globals()
        {
        }

        /// <summary>
        /// Gets the instance of this class.
        /// </summary>
        public static Globals Instance
        {
            get { return m_Instance ?? (m_Instance = new Globals()); }
        }

        /// <summary>
        /// Gets or sets the current target process.
        /// </summary>
        private Process currentProcess;
        public Process CurrentProcess
        {
            get
            {
                if (currentProcess == null)
                {
                    currentProcess = Process.GetProcessesByName("ffxiv").ToList().FirstOrDefault();
                }
                return currentProcess;
            }
            set
            {
                currentProcess = value;
            }
        }

        private ProcessModule processModule { get; set; }
        public ProcessModule ProcessModule
        {
            get
            {
                if (processModule == null)
                {
                    processModule = (from ProcessModule m in Globals.Instance.CurrentProcess.Modules
                                     where m.ModuleName.ToLower() == "ffxiv.exe"
                                     select m).SingleOrDefault();
                }
                return processModule;
            }
            set
            {
                processModule = value;
            }
        }

    }
}
